package com.hanthink.web.controller.app.label;

import com.hanthink.common.core.controller.BaseController;
import com.hanthink.common.core.domain.AjaxResult;
import com.hanthink.common.core.domain.model.LoginUser;
import com.hanthink.common.core.page.TableDataInfo;
import com.hanthink.common.utils.ServletUtils;
import com.hanthink.framework.web.service.TokenService;
import com.hanthink.system.domain.label.LabelRecord;
import com.hanthink.system.domain.label.LabelVerification;
import com.hanthink.system.mapper.equipment.EquipmentInfoMapper;
import com.hanthink.system.mapper.label.LabelRecordMapper;
import com.hanthink.system.service.label.ILabelRecordService;
import com.hanthink.system.service.label.ILabelVerificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * -Controller
 * 
 * @author hanthink
 * @date 2023-02-07
 */
@RestController
@RequestMapping("/app/label/LabelVerification")
public class LabelController extends BaseController
{
    @Autowired
    private ILabelVerificationService labelVerificationService;
    private ILabelRecordService labelRecordService;
    @Autowired
    private LabelRecordMapper labelRecordMapper;

    @Autowired
    private TokenService tokenService;
    /**
     * 查询列表
     */
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody LabelVerification labelVerification)
    {

        startPage();
        List<LabelVerification> list = labelVerificationService.getAppList(labelVerification);
        return getDataTable(list);
    }

//    @PostMapping("/add")
//    public void add(@RequestBody LabelRecord labelRecord)
//    {
//        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
//        String operName = loginUser.getUsername();
//        labelRecordService.insertLabelRecord(labelRecord, operName);
//
//    }


    @PostMapping("/add")
    public void  add(@RequestBody Map<String, Object> map)
    {
//        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
//        String operName = loginUser.getUsername();
//        labelRecordService.insertLabelRecord(labelRecord,operName);
//        return AjaxResult.success();

        Object customer = map.get("customer");
        Object production = map.get("production");
        Object frontlabel = map.get("frontlabel");
        Object backlabel = map.get("backlabel");
        Object antifakelabel = map.get("antifakelabel");
        Object creatdatetime = map.get("creatdatetime");
        Object creator = map.get("creator");

        LocalDateTime now = LocalDateTime.now();
        String a=now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")).toString();

        if(antifakelabel==null){
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("customer", customer.toString());
            params.put("production", production.toString());
            params.put("frontlabel", frontlabel.toString());
            params.put("backlabel", backlabel.toString());
            params.put("creatdatetime", a.toString());
            params.put("creator", creator.toString());
            labelRecordMapper.insertInfo(params);
        }else{
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("customer", customer.toString());
            params.put("production", production.toString());
            params.put("frontlabel", frontlabel.toString());
            params.put("backlabel", backlabel.toString());
            params.put("antifakelabel", antifakelabel.toString());
            params.put("creatdatetime", a.toString());
            params.put("creator", creator.toString());
            labelRecordMapper.insertInfo(params);
        }
    }


    /**
     * 获取客户信息和产品信息
     */
    @GetMapping("/getCustomerAndProduction")
    public Map<String,Object> getCustomerAndProduction()
    {
        Map<String,Object> map = labelVerificationService.getCustomerAndProduction();
        return map;
    }




}
